package com.mfs.common.utills;

/**
 * 计数器
 * @author mfs
 * @date 2022/07/11
 * */
public class Counter {
    private String name;
    private volatile int count;
    public Counter(String name) {
        this(name, 0);
    }

    public Counter (String name, int count) {
        this.name = name;
        this.count = count;
    }

    public synchronized int increase() {
        int cur = count;
        count = cur + 1;
        return cur;
    }

    public synchronized int decrease() {
        int cur = count;
        count = cur - 1;
        return cur;
    }

    public int count() {
        return count;
    }
}
